package com.cqhilink.iot.jobstandardmanagement.services.innerservice.impl.operateform;

import com.cqhilink.iot.jobstandardmanagement.facade.utils.TreeIconSkin;
import com.cqhilink.iot.jobstandardmanagement.facade.model.EntityType;
import com.cqhilink.iot.jobstandardmanagement.facade.model.EntityTypeProperty;
import com.cqhilink.iot.jobstandardmanagement.facade.model.Ztree;
import com.cqhilink.iot.jobstandardmanagement.facade.service.entitytype.JsmEntityTypePropertyService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.entitytype.JsmEntityTypeService;
import com.cqhilink.iot.jobstandardmanagement.facade.service.operateform.JsmOperateFormService;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by huangxueqian on 2017/3/2/002
 * 操作表单：操作记录 .
 */

public class JsmOperateFormServiceImpl implements JsmOperateFormService {

    @Autowired
    private JsmEntityTypePropertyService entityTypePropertyService ;

    @Autowired
    private JsmEntityTypeService entityTypeService ; // 生产实体类型



    /**
     * 根据一站一案  或者 操作单元
     * @param relateId
     * @param version
     * @return
     */
    @Override
    public List<Ztree> loadEntityTypeProperty(String keyword,String relateId,String entityTypeId,String entityId, BigDecimal version) {
        /**
         * 如果是生产实体类型后台未传值， 则代表查询整个的生产实体类型
         */
        List<Ztree> list = new ArrayList<>();
        // 设备类型判断为空
        if(entityTypeId ==null){
            EntityType entityType = new EntityType();
            if(keyword.equalsIgnoreCase(""))keyword = null ;
            entityType.setEntityTypeName(keyword);
            List<Ztree> entityTypes = entityTypeService.listTree(entityType);
              if(entityTypes!=null)  for(Ztree z : entityTypes){
                  z.setIsParent(true);
                  list.add(z);
                } ;
        }else{
            List<EntityTypeProperty> entityTypeProperties = entityTypePropertyService.outQueryList(entityTypeId);
            if(entityTypeProperties!=null){
                for(EntityTypeProperty etp : entityTypeProperties){
                    Ztree ztree = new Ztree();
                    ztree.setId(etp.getDevicePropertyId());
                    ztree.setName(etp.getPropertyName());
                    ztree.setpId(etp.getEntityTypeId());
                    ztree.setCellFormItemType(etp.getPropertyType());
                    ztree.setIconSkin(TreeIconSkin.ICON_ENTITY_CHARACTERISTICS.getDesc());
                    ztree.setOpen(true);
                    list.add(ztree);
                }
            }
        }




        return list ;
    }



}
